package Buttons 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.KeyboardEvent;
	import flash.geom.ColorTransform;
	import screens.NoteCanvas;
	import screens.PlayNoteTab;
	
	/**
	 * ...
	 * @author Andy Wolff
	 */
	public class PlayNoteButton extends MovieClip
	{
		private var view:NoteCanvas;
		private var tab:PlayNoteTab;
		private var which:int;
		public var held:Boolean;
		public var keyHeld:Boolean;
		public function PlayNoteButton(view:NoteCanvas,tab:PlayNoteTab,which:int) 
		{
			this.view = view;
			this.tab = tab;
			this.which = which;
			addEventListener(MouseEvent.MOUSE_DOWN, down);
			addEventListener(MouseEvent.MOUSE_UP, up);
			addEventListener(Event.ENTER_FRAME, step)
			addEventListener(MouseEvent.MOUSE_OUT, up);
		}
		/*
		private var prevNote:Note;
		public function makeNote(which:int):Note {
			
			if (prevNote != null && prevNote.getWhich() == which && playPos == prevNote.getEnd()) {
				fastForward(4); prevNote.extend(new Point(prevNote.getEnd() + 4, 0));
			}
			else { prevNote = new Note(currentInstrument, which, playPos, playPos); currentInstrument.addNote(prevNote); }
			return prevNote;
		}
		*/
		
		public function down(me:MouseEvent):void {
			held = true;
		}
		public function keyDown(k:KeyboardEvent):void {
			if (k.keyCode-49==which) keyHeld = true;
		}
		
		public function up(me:MouseEvent):void {
			held = false;
		}
		public function keyUp(k:KeyboardEvent):void {
			if (k.keyCode-49==which) keyHeld = false;
		}
		
		public function step(e:Event):void {
			if (held || keyHeld) {
				transform.colorTransform = new ColorTransform(0.5, 0.5, 0.5, 1);//view.buttonHeld(which);
				tab.makeNote(which);
			}
			else transform.colorTransform = new ColorTransform();
		}
	}

}